Collecting sympy
Downloading sympy-1.12-py3-none-any.whl (5.7 MB)
Requirement already satisfied, skipping upgrade: mpmath>=0.19 in c:\users\phonchi\anaconda3\lib\site-packages (from sympy) (1.1.0)
Installing collected packages: sympy
Attempting uninstall: sympy
Found existing installation: sympy 1.6.1
Uninstalling sympy-1.6.1:
Successfully uninstalled sympy-1.6.1
Successfully installed sympy-1.12
Note: you may need to restart the kernel to use updated packages.
Appendix N — Assignment 9
N.1 (1) Which of the following statement is False?
We can evaluate the values of special constants, like \(e\), \(\pi\), and \(\infty\) using
SymPy
.You can express one symbol in terms of another and perform substitutions accordingly, using the
subs()
method. For instance, you can substitute \(\cos(x)\) with \(\sin(x+\pi/2)\) by callingsubs({sp.cos(x):sp.sin(x+sp.pi/2)})
.nsolve()
function is a numerical version of thesolve()
function. Therefore, ifsolve()
function fails to find a solution,nsolve()
function will also fail to find a solution.The
lambdify()
function inSymPy
convertsSymPy
expressions into equivalent Python functions, enabling them to be computed numerically.
Ans: Double click to answer the question
- If
solve()
fails to find a solution, it doesn’t meannsolve()
will also fail. They use different methods and can handle different types of equations.
N.2 (2) Which of the following function can be use to display the expression in the reverse order, so that the terms of an expression are arranged according to the powers of x
, in ascending order?
init_printing()
evalf()
simplify()
lambdify()
Ans: Double click to answer the question
N.3 (3) Which of the following statement is False?
By default, the direction from which the limit is computed is negative in
SymPy
, unless the point of computation is positive or negative infinity.When constructing a matrix in
SymPy
, the approach is quite similar to that ofNumPy
. You provide a list of lists, where each inner list is a row of the matrix.By default, the
solve()
function will return the solutions in a list.In
sympy
, you can expand a trigonometric expression by settingtrig=True
in theexpand()
function.
Ans: Double click to answer the question
- By default, the direction from which the limit is computed is positive in
SymPy
.
N.4 (4) Which of the following operation will return the evaluation results rather than an unevaluated object?
sp.Limit(1/x, x, -sp.oo)
sp.Derivative(1/x, x)
sp.diff(x**2, x)
sp.Integral(x**2)
Ans: Double click to answer the question
N.5 (5) Which of the following function can be used to evaluate an expression to a floating-point number?
doit()
simplify()
lambdify()
evalf()
Ans: Double click to answer the question
N.6 (6) Consider the following two equations:
\[ \begin{align} x + y + z &= 6 \\ 2x + 3y + z &= 12 \\ 3x - 2y + z &=2 \end{align} \]
Try to find the pair of values (x, y)
that satisfies both equations using SymPy
. After that, substitute the values of x
and y
into the original equations to verify that the solutions are correct using SymPy
.
N.7 (7) Factoring the following polynomial, and finding its roots using SymPy
:
\[x^4-6x^3+x^2+24x+16\]
\(\displaystyle \left(x - 4\right)^{2} \left(x + 1\right)^{2}\)
N.8 (8) Find all the intersection points between \(f(x)=20-x^3\) and \(g(x)=6x^2 \times 1.12^x\) using SymPy
by first plotting the function and using the graph to narrow down the range of the intersection points. Then, use nsolve()
function to find the intersection points. Your results should be the coordinate values in numerical format.
Hint: You may find solve()
and nroots()
can not be used to solve this problem. In addition, you may need to zoom in around 0 to find all the possible intersection points.
N.9 (9) Try to evaluate the expression \(\log{3}+e\) to 20 precision (significant digits) using SymPy
.
N.10 (10) Try to solve the following problems using SymPy
:
Simplify the following expression: \(\tan(x)\times \cos(3x) \times \sin(x)\) so that the final results only contains sin(x)
and its power term (\(\sin^n(x)\)).
Hint: You can use simplify()
and expand()
functions to simplify the expression. You may find trig=True
option in expand()
function useful.